package com.sundaying.gooway.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;
import com.sundaying.gooway.entity.TopItem;
import com.sundaying.gooway.service.TopItemService;

public class TopItemAction extends ActionSupport {
	private TopItemService topItemService;
	private List<TopItem> topItemList;
	private TopItem topItem;
	private long id;

	// 将会被Struts2序列化为JSON字符串的对象
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	// 视图datagrid属性
	private int page;
	private int rows;
	private long total;

	public TopItemService getTopItemService() {
		return topItemService;
	}

	@Resource
	public void setTopItemService(TopItemService topItemService) {
		this.topItemService = topItemService;
	}

	public List<TopItem> getTopItemList() {
		return topItemList;
	}

	public void setTopItemList(List<TopItem> topItemList) {
		this.topItemList = topItemList;
	}

	public TopItem getTopItem() {
		return topItem;
	}

	public void setTopItem(TopItem topItem) {
		this.topItem = topItem;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public String add() {
		topItemService.add(topItem);
		return this.SUCCESS;
	}

	public String list() {
		topItemList = topItemService.list();
		return this.SUCCESS;
	}

	public String listByPage() {
		TopItem topItem = new TopItem();
		topItemList = topItemService.list(page, rows, "", "", topItem);
		total = topItemService.total(topItem);
		dataMap.clear();
		dataMap.put("total", total);
		dataMap.put("rows", topItemList);
		return this.SUCCESS;
	}

	public String update() {
		topItemService.update(topItem);
		return this.SUCCESS;
	}

	public String delete() {
		topItemService.delete(id);
		return this.SUCCESS;
	}
}
